ActiveReports 10 Server User Guide
UserContext in Multi-Tenant Reports
ActiveReports 10 Server User Guide > Samples and Walkthroughs > Walkthroughs > UserContext in Multi-Tenant Reports

The topic demonstrates how to provide specific report data to a current user by setting the UserContext attribute in a report.

In the developer version of ActiveReports, you can set the UserContext attribute in Page, RDL, and Section report, then upload the report to ActiveReports Server. On the Server, the UserContext attribute filters report data to display only data specific to the current user. The UserContext attribute is particularly helpful when you have multiple tenants, logging into the same portal and you want to restrict the data available to each tenant.

Note: The topic uses the Chinook database as a custom security provider. For information about the Chinook database, see https://chinookdatabase.codeplex.com.

To create a report for multiple tenants using the Chinook database

  1. In the ActiveReports Designer, under File, click New.
  2. In the Create New Report wizard, select Page Report and click OK.
  3. To connect to a data source, in the Report Explorer, right-click the Data Sources node and select the Add Data Source option.

  4. In the Report Data Source dialog, create a connection to the Chinook database. For information, see Connect to a Data Source
  5. To add a dataset, in the Report Explorer, right-click the Data Sources node and select the Add Data Set option.
    • In the DataSet dialog, on the General page, enter Invoice as the name of the dataset. 
    • On the Query page of this dialog, in the Query field enter the following SQL query.
      SQL Query
      Copy Code
      Select * from Invoice where CustomerID=@Invoice
      
    • On the Parameters page of this dialog, click the Add button.
    • In the Name field, enter Invoice and set its value to =[@Customer].
    • Click OK to close the dialog.
  6. From the Toolbox, drag the Table control onto the Design surface.

  7. Select the Table control and in the Properties window, set the DataSetName property to Invoice.

  8. In the Table's detail row, click the adorner in each cell to show a list of available fields from the data set and add the following fields to the cells.

    Cell Field
    Left Cell InvoiceID
    Middle Cell InvoiceDate
    Right Cell Total

To set the UserContext attribute

The UserContext attribute is set in the report parameter that will retrieve specific information for the user that is logged into the server. See Add Parameters for detailed information about parameters in a page report.

  1. In the Report Explorer, right-click the Parameters node and select Add Parameter. The Report Parameters dialog appears.
  2. On the General tab, set the Name to Customer, set the Data type to Integer and select the Hidden box.
  3. On the Available Values tab, select Non-queried and in the Value field, enter = Code.UserContext.GetValue("CustomerID").
  4. Click OK.

To format the table (optional)

There are many ways you can format the table that you have added to the report in ActiveReports Designer. See Table in the ActiveReports User Guide for more information on the formatting possibilities.

  1. Select the Table control and go to the Properties window to set the following properties.
    FixedSize 6.5in, 7in
    Location 0in, 0.5in
    RepeatHeaderOnNewPage True
    Size 6.4in, 0.7in
  2. Select the Table's detail row and in the Properties window set the TextAlign property to Left and the BorderStyle property to Solid.

  3. Select the middle cell (InvoiceDate) of the details row and in the Properties window set the Format property to d.
  4. Select the right cell of the Table Footer and go to the Properties window to set the following properties.
    Format c
    Value =Sum(Fields!Total.Value)

To upload the Page report to ActiveReports Server

  1. Connect to ActiveReports Server as described in Connecting to ActiveReports Server.
  2. Select the directory in the folders tree to choose the location in which to save the report on the server.
  3. Enter the report name in the Report name field as Invoices and click Save.

To set up the custom security provider

This topic uses the sample custom security provider project installed with ActiveReports Server. By default, this sample is in the following folder.

C:\ActiveReports 10 Server\SDK\Samples\ActiveTunes.SecurityProvider

For detailed steps on how to set up the custom security provider, see Deploy the Custom Security Provider for Debugging.

To set permissions for the report on ActiveReports Server

On ActiveReports Server, the report permissions have to be modified so that its multiple users can read it.

See To Manage Permissions to a Report on how to grant the Read permissions on the report.  

To preview the report on ActiveReports Server

  1. Open the ActiveReports 10 Server Report Portal.
  2. On the Login screen that appears, in the User Name field, enter a customer ID, for example, luisg@embraer.com.br.
  3. In the Password field, enter 1 (for the luisg@embraer.com.br customer ID).
  4. Click Login.
  5. In the ActiveReports Server Report Portal that appears, click the Preview report button for the Invoices report to see all invoices for the logged-in user.

See Also

Reference

SDK Tutorials

Administration